package com.corpdata.activiti.utils;

import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;

import com.corpdata.activiti.entity.ProcessInfo;

import java.util.HashMap;
import java.util.Map;

public class ActivitiUtils {

	/**
	 * 节点对应的中文名称
	 * 
	 * @param type
	 * @return
	 */
	public static String parseToZhType(String type) {
		Map<String, String> types = new HashMap<String, String>();
		types.put("userTask", "用户任务");
		types.put("serviceTask", "系统任务");
		types.put("startEvent", "开始节点");
		types.put("endEvent", "结束节点");
		types.put("exclusiveGateway", "条件判断节点(系统自动根据条件处理)");
		types.put("inclusiveGateway", "并行处理任务");
		types.put("callActivity", "子流程");
		return types.get(type) == null ? type : types.get(type);
	}

	/**
	 * 抽取流程实例需要返回的内容
	 * 
	 * @param processDefinition
	 * @param deployment
	 * @return
	 */
	public static ProcessInfo toProcessVO(ProcessDefinition processDefinition, Deployment deployment) {
		if (null == processDefinition || null == deployment) {
			// throw new SlifeException(HttpCodeEnum.INVALID_REQUEST);
		}
		ProcessInfo dto = new ProcessInfo();
		dto.category = processDefinition.getCategory();
		dto.processonDefinitionId = processDefinition.getId();
		dto.key = processDefinition.getKey();
		dto.name = deployment.getName();
		dto.revision = processDefinition.getVersion();
		dto.deploymentTime = deployment.getDeploymentTime().getTime();
		dto.xmlName = processDefinition.getResourceName();
		dto.picName = processDefinition.getDiagramResourceName();
		dto.deploymentId = deployment.getId();
		dto.suspend = processDefinition.isSuspended();
		dto.description = processDefinition.getDescription();
		return dto;
	}
}
